package Test2;

public class Dog {
	//封装第一步：属性私有
	private String name;
	private int health;
	private String sex;
	private int love;
	//封装第二步：写公有的setter/getter方法
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getHealth() {
		return health;
	}
	//设置健康值
	public void setHealth(int health) {
		if(health<1 || health>100) {
			System.out.println("健康值非法，恢复默认值！");
			health=60;
		}
		this.health = health;
	}
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	public int getLove() {
		return love;
	}
	public void setLove(int love) {
		if(love<1 || love>10) {
			System.out.println("亲密度非法，恢复默认值！");
			love=5;
		}
		this.love = love;
	}
	public void show() {
		System.out.println("宠物自白："+"\n我叫"+name+",性别是"+sex+",健康值是"+health+"，与主人的亲密度是"+love);
	}
	
}
